﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;

namespace DingTalkAgent.Web.Controllers
{
    public class SysHomeController : Common.adminBaseController
    {
        public ActionResult Index()
        {
            SqlData.Roles dh = new SqlData.Roles();
            var m = dh.IEnumBuildNav(_view_Admin_Info.RoleID).ToList();
            SqlData.Dictionary dic_dh = new SqlData.Dictionary();
            var list = dic_dh.IEnumGetList(" Parent_ID=29 ").ToList();

            return View(new Models.HomeData() { sysNavList = m, dictionarylist = list, account = _view_Admin_Info });
        }

        [Common.myCommon]
        public ActionResult UpdatePassWord()
        {
            return View();
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Common.myCommon]
        public ActionResult UpdatePassWord(FormCollection froms)
        {
            try
            {
                string Password = Request["Password"].ToString();
                if (Password.Length < 6)
                {
                    return Content("密码长度最少6位！");
                }
                string oldPassword = Request["oldPassword"].ToString();

                //管理员密码修改
                SqlData.Admin_Info dh = new SqlData.Admin_Info();
                if (dh.UpdatePassWord(_view_Admin_Info.UserID, Password, oldPassword))
                {
                    //操作记录
                    Models.Operation.Add(_view_Admin_Info.UserID.ToString(), "密码密码", "成功修改密码", _view_Admin_Info.Name);
                    return Content("true");
                }
                else
                {
                    return Content("修改密码失败！可能原因，旧密码输入不对！");
                }
            }
            catch (Exception ex)
            {
                //错误日志
                Models.ErrorLog.Add(_view_Admin_Info.UserID, "/home/UpdatePassWord", ex.Message, _view_Admin_Info.Name);
                return Content(ConfigHelper.getErrorMsg);
            }
        }

    }
}